<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">

    <body>
        <ui:composition template="../templates/default3.xhtml">
            <ui:define name="content">
                <h:form id="addShippingOrder" binding="#{shippingManagerBean.loadAddShippingOrder}">
                    <p:panel id="purchases" header="Purchase Items">
                        <p:messages />

                        <p:dataTable id="purchaseItems" var="purchaseItem" value="#{shippingManagerBean.purchaseItems}" 
                                     emptyMessage="No purchase items found with given criteria."
                                     selection="#{shippingManagerBean.selectedPurchaseItem}"
                                     selectionMode="single">
                            <p:column headerText="Product" sortBy="#{purchaseItem.product.name}">  
                                <h:outputText value="#{purchaseItem.product.name}">
                                </h:outputText>
                            </p:column> 
                            <p:column headerText="Quantity" sortBy="#{purchaseItem.quantity}">  
                                <h:outputText value="#{purchaseItem.quantity}">
                                </h:outputText>
                            </p:column> 
                            <p:column headerText="Total Amount" sortBy="#{purchaseItem.subTotal}">  
                                <h:outputText value="#{purchaseItem.subTotal}">  
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </p:column> 
                            <p:column headerText="Outstanding Amount" sortBy="#{purchaseItem.outstandingAmount}">  
                                <h:outputText value="#{purchaseItem.outstandingAmount}">
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </p:column> 
                            <p:column headerText="Status" sortBy="#{purchaseItem.status}">  
                                <h:outputText value="#{purchaseItem.status}">
                                </h:outputText>
                            </p:column> 
                        </p:dataTable>
                    </p:panel>
                    <p:panel id="addShippingOrder" header="Add a Shipping Order">
                        <table border="0" width="100%">
                            <tr>
                                <td width="150px">Delivery Date:</td>
                                <td>
                                    <p:calendar required="true" requiredMessage="Delivery date is required." 
                                                value="#{shippingManagerBean.deliveryDate}" pattern="dd-MM-yyyy" 
                                                title="Date of delivery."/> 
                                    <font class="fieldNote">*</font>
                                </td>
                            </tr>
                            <tr>
                                <td width="150px"></td>
                                <td>
                                    <p:commandButton id="btnAddShippingOrder" value="Add Shipping Order"
                                                     ajax="true" title="Add a shipping order."
                                                     update="purchases"
                                                     actionListener="#{shippingManagerBean.addAShippingOrder}"/>
                                    <p:commandButton id="btnBackFromAddShippingOrder" value="Back"
                                                     immediate="true" ajax="true"
                                                     title="Go back to the previous page."
                                                     actionListener="#{shippingManagerBean.back}"/>
                                </td>
                            </tr>
                        </table>
                    </p:panel>
                </h:form>
                <p:ajaxStatus onstart="statusDialog.show();" onsuccess="statusDialog.hide();"/>  
                <p:dialog modal="true" widgetVar="statusDialog" header="Please wait..."   
                          draggable="false" closable="false" resizable="false">  
                    <p:graphicImage value="../resources/images/ajaxloadingbar.gif" />  
                </p:dialog>
            </ui:define>
        </ui:composition>
    </body>
</html>
